<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>活体白名单</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户姓名</div>
                    <div class="field">
                        <input name="cstNmSearch" id="cstNmSearch" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">证件号</div>
                    <div class="field">
                        <input name="certNoSearch" id="certNoSearch" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox formBtns notRight">
                    <span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
                    <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
                    <span id="addBtn" onclick="add();" class="sq-button-round">新增</span>

                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        initForm();
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
        initEvent();
    });

    //初始化事件
    function initEvent() {
    }


    function initForm(){
        $("#searchBar").ligerForm();
    }

    //查询按钮事件
    function searchBtn(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
            grid.setParm(name,data[name]);
        };
        grid.reload();
    }

    //查询参数
    function getSearchParams(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
    }

    //初始化列表
    function initGrid() {
        var _url = '<%=path%>/custpay/cmmwhitelist/initList.do';
        $("#ligergrid1").ligerGrid({
            url: _url,
            method: 'get',
            parms:getSearchParams(),
            columns: [
                {display: '客户姓名', name: 'cstNm', align: 'left', width: 100},
                {display: '证件号', name: 'certNo', align: 'left', width: 200},
                {display: '证件类型', name: 'certTypCdNm', align: 'left', width: 100},
                {display: '名单类型', name: 'listTypCdNm', align: 'left', width: 100},
                {display: '开始时间', name: 'startTm', align: 'left', width: 150, render: renderDate},
                {display: '结束时间', name: 'endTm', align: 'left', width: 150, render: renderDate},
                {display: '状态', name: 'isValidNm', align: 'center', width: 100},
                {
                    display: '操作',width: 150,align: 'left',
                    render: function (rowdata, rowindex, value){
                        var h3 = '';
                        h3 += '<a class="sq-button-hasicon" href="javascript:modifyRow(' + "'" + rowdata.id + "'" + ')"><i class="sqBtnIco_4"></i>修改</a>';
                        h3 += '<a class="sq-button-hasicon" href="javascript:del(' + "'" + rowdata.id + "'" + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        return h3;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            }
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
    }

    //清空按钮事件
    function clearBtn(){
        $("#resetBtn").click();  //重置 input-text
        var form = new liger.get("searchBar");
        form.setData({  //重置select等特殊表单
            "cstNmSearch":"",
            "certNoSearch":""
        });
    }

    //新增
    function add(){
        $.ligerDialog.SQopen({
            width: 900,
            height:700,
            title : '新增活体白名单',
            url:'<%=path%>/custpay/cmmwhitelist/toModifyPage.do',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) {
                        Dialog.onOk();
                    }
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) {
                        Dialog.onCancel()
                    };
                }
            }
            ]
        });
    }



    //修改方法
    function modifyRow(_id){
        $.ligerDialog.SQopen({
            width: 900,
            height:700,
            title : '修改活体白名单信息',
            url:'<%=path%>/custpay/cmmwhitelist/toModifyPage.do?id='+_id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) {
                        Dialog.onOk();
                    }
                }
            }, {
                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }


    //删除
    function del(_id) {
        if (!_id)return;
        $.ligerDialog.confirm('确定删除吗?', function (flag) {
            if (flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data:{id:_id},
                url: '<%=path%>/custpay/cmmwhitelist/removeById.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload($('.pcontrol input', grid.toolbar).val());
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }



    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>
</body>
</html>